// import 'dart:async';
// import 'dart:math';
// import 'package:amap_flutter_location/amap_flutter_location.dart';
// import 'package:amap_flutter_location/amap_location_option.dart';
// import 'package:lcapp/data/location_data_entity.dart';
// import 'package:lcapp/model/event/event_bus.dart';
// import 'package:lcapp/model/permission/permission_operate.dart';
// import 'package:lcapp/routes/route.dart';
//
//
// class AmapTool {
//   static AMapFlutterLocation _locationPlugin = new AMapFlutterLocation();
//   static StreamSubscription<Map<String, Object>> _locationListener;
//   static LocationDataEntity locationEntity = LocationDataEntity();
//   static bool isOpenLocation = false;
//   static bool canUpdateUserInfo = false;
//   static bool isShowToastShowPop = true;
//
//   ///设置定位参数
//   static void _setLocationOption() {
//     AMapLocationOption locationOption = new AMapLocationOption();
//
//     ///是否单次定位
//     locationOption.onceLocation = true;
//
//     ///是否需要返回逆地理信息
//     locationOption.needAddress = true;
//
//     ///逆地理信息的语言类型
//     locationOption.geoLanguage = GeoLanguage.DEFAULT;
//     locationOption.desiredLocationAccuracyAuthorizationMode =
//         AMapLocationAccuracyAuthorizationMode.ReduceAccuracy;
//     locationOption.fullAccuracyPurposeKey = "AMapLocationScene";
//
//     ///设置Android端连续定位的定位间隔
//     locationOption.locationInterval = 2000;
//
//     ///设置Android端的定位模式<br>
//     ///可选值：<br>
//     ///<li>[AMapLocationMode.Battery_Saving]</li>
//     ///<li>[AMapLocationMode.Device_Sensors]</li>
//     ///<li>[AMapLocationMode.Hight_Accuracy]</li>
//     locationOption.locationMode = AMapLocationMode.Hight_Accuracy;
//
//     ///设置iOS端的定位最小更新距离<br>
//     locationOption.distanceFilter = -1;
//
//     ///设置iOS端期望的定位精度
//     /// 可选值：<br>
//     /// <li>[DesiredAccuracy.Best] 最高精度</li>
//     /// <li>[DesiredAccuracy.BestForNavigation] 适用于导航场景的高精度 </li>
//     /// <li>[DesiredAccuracy.NearestTenMeters] 10米 </li>
//     /// <li>[DesiredAccuracy.Kilometer] 1000米</li>
//     /// <li>[DesiredAccuracy.ThreeKilometers] 3000米</li>
//     locationOption.desiredAccuracy = DesiredAccuracy.Best;
//
//     ///设置iOS端是否允许系统暂停定位
//     locationOption.pausesLocationUpdatesAutomatically = false;
//
//     ///将定位参数设置给定位插件
//     _locationPlugin.setLocationOption(locationOption);
//   }
//
//   ///开始定位
//   static void startLocation({
//     bool updateInfo = false, // 是否更新用户信息
//     bool isShowToast = false, // 是否吐司提示
//   }) {
//     canUpdateUserInfo = updateInfo;
//     isShowToastShowPop = isShowToast;
//     getLocationPermission(
//         ASRRoute.navigatorKey.currentContext,
//         () {
//           isOpenLocation = true;
//           _locationListener ??= _locationPlugin
//                 .onLocationChanged()
//                 .listen((Map<String, dynamic> result) {
//               print('定位信息====' + result.toString());
//               if (result['errorCode'] == null) {
//                 locationEntity = LocationDataEntity().fromJson(result);
//                 locationEntity.coordinate =
//                     '${locationEntity.longitude},${locationEntity.latitude}';
//                 eventBus.fire(LocationState());
//                 print('定位信息====' + locationEntity.toJson().toString());
//               }else{
//                 locationEntity.longitude = '116.30';
//                 locationEntity.latitude = '37.45';
//               }
//               _stopLocation();
//             });
//
//           ///开始定位之前设置定位参数
//           _setLocationOption();
//           _locationPlugin.startLocation();
//         },
//         isShowToast: isShowToast,
//         errorCallBack: () {
//           isOpenLocation = false;
//           locationEntity.longitude = '116.30';
//           locationEntity.latitude = '37.45';
//         });
//   }
//
//   ///停止定位
//   static void _stopLocation() {
//     _locationPlugin.stopLocation();
//   }
//
//   /// 单位：KM
//   static double getDistance(double lat1, double lng1,
//       {double lat2, double lng2}) {
//     if (lat2 == null || lng2 == null) {
//       if (AmapTool.locationEntity.latitude == null || AmapTool.locationEntity.longitude == null) {
//         //没有获取到当前位置信息
//         return null;
//       }
//       lat2 = double.parse(AmapTool.locationEntity.latitude);
//       lng2 = double.parse(AmapTool.locationEntity.longitude);
//     }
//     double def = 6378137.0;
//     double radLat1 = _rad(lat1);
//     double radLat2 = _rad(lat2);
//     double a = radLat1 - radLat2;
//     double b = _rad(lng1) - _rad(lng2);
//     double s = 2 *
//         asin(sqrt(pow(sin(a / 2), 2) +
//             cos(radLat1) * cos(radLat2) * pow(sin(b / 2), 2)));
//     return (s * def).roundToDouble() / 1000;
//   }
//
//   static double _rad(double d) {
//     return d * pi / 180.0;
//   }
// }
